//
//  LGCarePlanManageController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/13.
//  管理照护计划

#import "LGCarePlanManageController.h"
//患者档案
#import "LGPatientDetailController_YHJK.h"
#import "LGPatientDetailController2.h"
//照护计划
#import "LGPatientCarePlanController.h"
//签约历史
#import "LGPatientSignHistoryController.h"
#import "LGCarePlanManageCell.h"
@interface LGCarePlanManageController ()<UITableViewDelegate,UITableViewDataSource,LGCarePlanManageDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation LGCarePlanManageController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationView.title = @"管理照护计划";
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.tableView frame:CGRectMake(0, viewPix(119), Screen_W, Screen_H-topBarHeight-viewPix(119))];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/workbench/careplanPending" parameters:@{} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(code == 200){
            self.numberLabel.text = LGNSString(returnData[@"count"]);
            self.dataArray = returnData[@"lists"];
            [self.tableView reloadData];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    }];
}

//患者档案
-(void)checkPatientDetail:(NSDictionary *)tempDic{
    NSString *nodePage = LGNSString(tempDic[@"nodepage"]);
    if ([nodePage isEqualToString:@"1"]) {
        //市一慢阻肺
        LGPatientDetailController2 *controller = [[LGPatientDetailController2 alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        //其他
        LGPatientDetailController_YHJK *controller = [[LGPatientDetailController_YHJK alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

//照护计划
-(void)checkCarePlan:(NSString *)patientid diseaseCode:(nonnull NSString *)diseaseCode levelid:(nonnull NSString *)levelid{
    LGPatientCarePlanController *controller = [[LGPatientCarePlanController alloc]init];
    controller.diseaseCode = diseaseCode;
    controller.patientid = patientid;
    controller.levelid = levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGCarePlanManageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    cell.delegate = self;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    LGPatientSignHistoryController *controller = [[LGPatientSignHistoryController alloc]init];
    controller.patientid = LGNSString(tempDic[@"patient_id"]);
    controller.levelid = LGNSString(tempDic[@"level_id"]);
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark
#pragma mark ====> 创建控件
-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, topBarHeight, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGCarePlanManageCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [self tableHeaderView];
    }
    return _tableView;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _numberLabel;
}

-(UIView *)tableHeaderView{
    UIView *baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(119))];
    baseView.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.frame = CGRectMake(0,0,Screen_W,viewPix(111));
    layer.startPoint = CGPointMake(0.5, 0);
    layer.endPoint = CGPointMake(0.5, 1);
    layer.colors = @[(__bridge id)[UIColor colorWithString:@"#E5F3FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F9FE"].CGColor, (__bridge id)[UIColor colorWithString:@"#FEFEFF"].CGColor];
    layer.locations = @[@(0), @(0.4f), @(1.0f)];
    [baseView.layer addSublayer:layer];
    
    UILabel *titleLabel = [UILabel lableWithText:@"需管理数量：" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    [baseView addSubview:titleLabel];
    [baseView addSubview:self.numberLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(baseView).offset(viewPix(16));
        make.left.equalTo(baseView).offset(viewPix(22));
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right);
        make.centerY.equalTo(titleLabel);
    }];
    
    UIButton *addButton = [UIButton buttonWithTitle:@"待新增：" titleFont:LGFontWeight(13, UIFontWeightMedium) textColor:@"#FDB33D" imageName:@"照护计划-待新增"];
    addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    addButton.frame = CGRectMake(viewPix(22), viewPix(49), viewPix(70), viewPix(20));
    addButton.titleEdgeInsets = UIEdgeInsetsMake(0, 3, 0, 0);
    [baseView addSubview:addButton];
    UILabel *addLabel = [UILabel lableWithText:@"购买服务包的患者，未新增照护计划任务" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    [baseView addSubview:addLabel];
    [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(addButton.mas_right);
        make.centerY.equalTo(addButton);
    }];
    
    UIButton *sureButton = [UIButton buttonWithTitle:@"待确认：" titleFont:LGFontWeight(13, UIFontWeightMedium) textColor:@"#2FBC93" imageName:@"照护计划-待确认"];
    sureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    sureButton.frame = CGRectMake(viewPix(22), viewPix(77), viewPix(70), viewPix(20));
    sureButton.titleEdgeInsets = UIEdgeInsetsMake(0, 3, 0, 0);
    [baseView addSubview:sureButton];
    UILabel *sureLabel = [UILabel lableWithText:@"未确认出院病情证明书识别的任务" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    [baseView addSubview:sureLabel];
    [sureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(sureButton.mas_right);
        make.centerY.equalTo(sureButton);
    }];
    
    return baseView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
